var start = function() {
	/**
	 * 首页广告
	 */
	var J_event = document.getElementById("J_event");
	var closeAds = document.getElementById("closeAds");
	closeAds.onclick = function(e) {
		var e = e || event;
		e.stopPropagation();
		J_event.style.display = "none";
	}
	
	/**
	 * 显示全国各省
	 */
	var listAdd = ["北京", "上海", "天津", "重庆", "河北", "山西", "河南", "辽宁", "吉林", "黑龙江", "内蒙古", "江苏", "山东", "安徽", "浙江", "福建", "湖北", "湖南", "广东", "广西", "江西", "四川", "海南", "贵州", "云南", "西藏", "陕西", "甘肃", "青海", "宁夏", "新疆", "港澳", "台湾", "钓鱼岛", "海外"];
	var liAddress = document.getElementById("liAddress");
	var addressText = document.getElementById("addressText");
	var addressDiv = document.getElementById("addressDiv");
	liAddress.onmouseenter = function(){
		addressDiv.style.display = 'block';
		liAddress.style.background = '#fff';
		liAddress.style.border = 'solid 1px #dddddd';
		liAddress.style.borderBottom = 'none';
	}
	liAddress.onmouseleave = function(){
		liAddress.timer = setTimeout(function(){
			addressDiv.style.display = 'none';
			liAddress.style.background = '';
			liAddress.style.border = 'none';
		},500)
	}
	addressDiv.onmouseenter = function(){
		clearTimeout(liAddress.timer);
		this.style.display = 'block';
	}
	addressDiv.onmouseleave = function(){
			addressDiv.style.display = 'none';
			liAddress.style.background = '';
			liAddress.style.border = 'none';
	}
	
	var len = listAdd.length;
	for(var i = 0;i<len;i++){
		var divItem = document.createElement("div");
		divItem.className = 'addressItem';
		var a = document.createElement("a");
		a.href = "javascript:void(0);"
		a.innerText = listAdd[i];
		if(addressText.innerText == listAdd[i]){
			a.className = 'sstyle';
			a.style.color = "#fff"
		}else{
		}
		a.onmouseenter = (function(num){
			return function(){
				for(var j = 0;j<addressDiv.children.length;j++){
					if(addressText.innerText == listAdd[j]){
						addressDiv.children[j].children[0].style.background = '#f10215';
						//addressDiv.children[j].children[0].style.color = "#fff"
					}else if(addressText.innerText != listAdd[j]&&j==num){
						addressDiv.children[j].children[0].style.background = '#F8F8F8';
					}
					else{
						addressDiv.children[j].children[0].style.background = '#FFFFFF';
					}
				}
			}
		})(i)
		a.onclick = (function(num){
			return function(){
				addressText.innerText = listAdd[num];
				addressDiv.style.display = 'none';
				for(var j = 0;j<addressDiv.children.length;j++){
					if(addressText.innerText == listAdd[j]){
						addressDiv.children[j].children[0].style.background = '#f10215';
						addressDiv.children[j].children[0].style.color = "#fff"
					}else{
						addressDiv.children[j].children[0].style.color = '#999';
						addressDiv.children[j].children[0].style.background = '#FFFFFF';
					}
				}
			}	
		})(i)
		divItem.appendChild(a);
		addressDiv.appendChild(divItem);
	}
	
	/**
	 * 手机京东
	 */
	var shoujijd = document.getElementById("shoujijd");
	var jd_mobile = document.getElementById("jd_mobile");
	var jdCode = document.getElementById("jdCode");
	shoujijd.onmouseenter = function(){
		clearTimeout(shoujijd.timer);
		clearTimeout(jd_mobile.timer);
		jd_mobile.style.display = 'block';
	}
	shoujijd.onmouseleave = function(){
		shoujijd.timer = setTimeout(function(){
			jd_mobile.style.display = 'none';
		},200)
	}
	jdCode.onmouseenter = function(){
		clearTimeout(shoujijd.timer);
		jd_mobile.style.display = 'block';
	}
	jd_mobile.onmouseleave = function(){
		jd_mobile.timer = setTimeout(function(){
			jd_mobile.style.display = 'none';
		},200)
	}
	
	/**
	 * menu详情页
	 */
	var menuCaidan = document.getElementById("menuCaidan");
	var menuDetail = document.getElementById("menuDetail");
	var lenMenu = menuCaidan.children.length;
	for(var i = 0;i<lenMenu;i++){
		menuCaidan.children[i].onmouseenter = (function(num){
			return function(){
				for(var j = 0;j<lenMenu;j++ ){
					menuDetail.style.display = 'block';
					if(j==num){
						menuCaidan.children[j].className = "cate_menu_item cate_menu_item_on";
						menuDetail.children[j].style.display = 'block';
					}else{
						menuDetail.children[j].style.display = 'none';
						menuCaidan.children[j].className = "cate_menu_item";
					}
				}
			}
		})(i)
	}
	menuCaidan.onmouseenter = function(){
		clearTimeout(menuDetail.time);
	}
	menuCaidan.onmouseleave = function(){
		menuCaidan.time = setTimeout(function(){
			menuDetail.style.display = 'none';
			for(var i = 0;i<lenMenu;i++){
				menuCaidan.children[i].className = "cate_menu_item";
			}
		},200)
	}
	menuDetail.onmouseenter = function(){
		clearTimeout(menuCaidan.time);
		clearTimeout(menuDetail.time);
		for(var i = 0;i<lenMenu;i++){
			clearTimeout(menuCaidan.children[i].timeleave);
		}
	}
	menuDetail.onmouseleave = function(){
		menuDetail.time = setTimeout(function(){
			menuDetail.style.display = 'none';
			for(var i = 0;i<lenMenu;i++){
				menuCaidan.children[i].className = "cate_menu_item";
			}
		},200)
	}
	
	
	/**
	 * 图片上传 搜索
	 */
	var xiangji = document.getElementById("xiangji");
	xiangji.onclick = function(e){
		var e = e || event;
		e.stopPropagation();
		var photofile = document.getElementById("photofile");
		photofile.onclick = function(e){
			var e = e || event;
			e.stopPropagation();
		}
	}
	
	/**
	 * 输入框中智能推荐
	 */
	var searchData = ["世界那么大我想","世界那么33大我想去看看","世q大我想去看看","世界那2想去看看","世777么大我想去看看","1235去看看","世8675去看看","世界那么大我5444看","世界那么2455","世界那么大我54看","关闭"]
	var shopCount = ["约4416个商品","约1416个商品","约7516个商品","约448个商品","约916个商品","约1256个商品","约8546个商品","约9316个商品","约3516个商品","约44146个商品"]
	var slen = searchData.length;
	var tuijian = document.getElementById("shelper");
	var search_text = document.getElementById("search_text");
	tuijian.onmouseleave = function(){
		setTimeout(function(){
			tuijian.style.display = 'none';
		},500)
	}
	search_text.onfocus = function(){
		tuijian.style.display = "block";
		if(tuijian.children.length!=0){
			
		}else{
			for(var i = 0;i<slen-1;i++){
			var lis = document.createElement("li"); 	
			var divl = document.createElement("div"); 	
			var divr = document.createElement("div");
			divl.className = 'search_item';
			divl.innerText = searchData[i];
			divr.className = 'search_count';
			divr.innerText = shopCount[i];
			lis.appendChild(divl);
			lis.appendChild(divr);
			lis.onmouseenter = (function(num){
				return function(){
					clearTimeout(search_text.timer);
					for(var j=0;j<slen-1;j++){
						if(j==num){
							tuijian.children[j].style.background = "#ccc";
						}else{
							tuijian.children[j].style.background = "#fff";
						}
					}
				}
			})(i);
			
			lis.onclick = (function(num){
				return function(){
					search_text.value = searchData[num];
					tuijian.style.display = 'none';
				}
			})(i)
			tuijian.appendChild(lis);
		}
		}
	}
	
	/**
	 * 购物车监听事件
	 */
	var gouwuche = document.getElementById("gouwuche");
	var carDetail = document.getElementById("carDetail");
	gouwuche.onmouseenter = function(){
		clearTimeout(gouwuche.timer);
		carDetail.style.display = 'block';
		this.style.borderBottom = "none";
	}
	gouwuche.onmouseleave = function(){
		gouwuche.timer = setTimeout(function(){
			carDetail.style.display = 'none';
			gouwuche.style.borderBottom = "#ccc solid 1px";
		},500)
	}
	carDetail.onmouseenter = function(){
		clearTimeout(gouwuche.timer);
		this.style.display = 'block';
	}
	carDetail.onmouseleave = function(){
		this.style.display = 'none';
		gouwuche.style.borderBottom = "#ccc solid 1px";
	}
	
	/**
	 * 热搜关键字
	 */
	var hotwords = document.getElementById("hotwords");
	var hotwordsData = ["家电秒杀","满500减100","特惠农机","阿玛尼","品质家电","除湿机","加绒裤男","粽情端午","移动一盘2t"];
	var lenHot = hotwordsData.length;
	for(var i = 0;i<lenHot;i++){
		var ha = document.createElement("a");
		ha.href = "javascript:void(0);";
		ha.innerText = hotwordsData[i];
		hotwords.appendChild(ha);
	}
	
	/**
	 * 悬浮搜索框,fixed
	 */
	var xuanfu = document.getElementById("xuanfu");
	document.onscroll = function(){
		var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
		if(scrollTop>600){
			xuanfu.style.display = 'block';
		}else{
			xuanfu.style.display = 'none';
		}
	}
	
	/**
	 * nav导航
	 */
	var groupData = [["秒杀","优惠券","闪购","拍卖"],["服装城","京东超市","生鲜","全球购"],["京东金融"]];
	var lianjie = [["http://miaosha.jd.com","http://a.jd.com","http://red.jd.com","http://paimai.jd.com"],["http://channel.jd.com/fashion.html","http://chaoshi.jd.com","http://fresh.jd.com","http://www.jd.hk"],["http://jr.jd.com"]]
	var navgroup1 = document.getElementById("nav-group1");
	var navgroup2 = document.getElementById("nav-group2");
	var navgroup3 = document.getElementById("nav-group3");
	for(var i = 0;i<groupData.length;i++){
		for(var j = 0;j<groupData[i].length;j++){
			var navli = document.createElement("li");
			var navlia = document.createElement("a");
			navlia.innerText = groupData[i][j];
			navlia.href = lianjie[i][j];
			navlia.target = "_blank";
			navli.appendChild(navlia);
			if(i==0){
				navgroup1.appendChild(navli);
			}
			if(i==1){
				navgroup2.appendChild(navli);
			}
			if(i==2){
				navgroup3.appendChild(navli);
			}
		}
	}
	
	/**
	 * 轮播图片功能实现
	 */
	var picData = ["img/lb1.jpg","img/lb2.jpg","img/lb3.jpg","img/lb4.jpg","img/lb5.jpg","img/lb6.jpg","img/lb7.jpg","img/lb8.jpg"]
	var lunbo_wrap = document.getElementById("lunbo_wrap");
	var lunbotu = document.getElementById("lunbotu");
	var slider_indicator = document.getElementById("slider_indicator");
	var lb_prev = document.getElementById("lb_prev");
	var lb_next = document.getElementById("lb_next");
	var lenlb = picData.length;
	//生成轮播的8张图片的布局
	for(var i=0;i<lenlb;i++){
		var lbli = document.createElement("li");
		var lblia = document.createElement("a");
		var lbliaimg = document.createElement("img");
		if(i==0){
			lbli.className = 'slider_item slider_indicator_btn_first';
		}else{
			lbli.className = 'slider_item';
		}
		lblia.className = 'slider_item_lk';
		lbliaimg.className = 'slider_item_img';
		lbliaimg.src = picData[i];
		lblia.href = "http://www.jd.com";
		lblia.target = "_blank";
		lblia.appendChild(lbliaimg);
		lbli.appendChild(lblia);
		lunbotu.appendChild(lbli);
	}
	//为包裹轮播外层的元素添加鼠标进入事件
	lunbo_wrap.onmouseenter = function(){
		clearInterval(lunbotu.tabtime);
		lb_prev.style.display = 'block';
		lb_next.style.display = 'block';
	}
	//为包裹轮播外层的元素添加鼠标离开事件
	lunbo_wrap.onmouseleave = function(){
		var e = e || event;
		e.stopPropagation();
		lunbotu.tabtime = setInterval(function(){
			tabPoint();
			tabImg();
		},2000)
		lb_prev.style.display = 'none';
		lb_next.style.display = 'none';
	}
	//为左箭头添加进入事件
	lb_prev.onmouseenter = function(e){
		var e = e || event;
		e.stopPropagation();
		lb_prev.style.backgroundColor = '#333';
		this.onclick = function(){
			if(index==1){
				index=7;
				tabPoint();
				teshuTabimg();
			}else{
				index-=2;
				tabPoint();
				teshuTabimg();
			}
		}
	}
	//为左箭头添加离开事件
	lb_prev.onmouseleave = function(){
		lb_prev.style.backgroundColor = 'rgba(0,0,0,0.1)';
	}
	//为右箭头添加进入事件
	lb_next.onmouseenter = function(){
		lb_next.style.backgroundColor = '#333';
		this.onclick = function(){
			if(index==8){
				index=0;
				tabPoint();
				teshuTabimg();
			}else{
				//index+=1;
				tabPoint();
				teshuTabimg();
			}
		}
	}
	//为左箭头添加离开事件
	lb_next.onmouseleave = function(){
		lb_next.style.backgroundColor = 'rgba(0,0,0,0.1)';
	}
	//为轮播图中的小圆点添加进入事件
	for(let k=0;k<lenlb;k++){
		slider_indicator.children[k].onmouseenter = function(){
			index = k;
			tabPoint();
			teshuTabimg();
		}
	}
	
	var index = 1;
	//轮播定时器
	lunbotu.tabtime = setInterval(function(){
		tabPoint();
		tabImg();
	},2000)
	//控制当前点以前其他小圆点的样式
	function tabPoint(){
		for(var i = 0;i<lenlb;i++){
			slider_indicator.children[i].className = " slider_indicator_btn";
		}
		if(index==8){
			index=0;
		}
		slider_indicator.children[7].className = " slider_indicator_btn slider_indicator_btn_last";
		slider_indicator.children[index].className = " slider_indicator_btn activePoint";
		if(index==7){
			slider_indicator.children[index].className = " slider_indicator_btn activePoint slider_indicator_btn_last";
		}
	}
	//var op=0,op1=1;
	//轮播图片的显示隐藏
	function tabImg(){
		for(var i = 0;i<lenlb;i++){
			if((index)==i){
//				lunbotu.children[i].timer = setInterval(function(){
//					if(op>=1){
//						clearInterval(lunbotu.children[i].timer);
//						op=0;
//					}
//					op+=0.1;
//					lunbotu.children[i].style.opacity = op;
//					lunbotu.children[i].style.zIndex = op;
//				},1000)
				lunbotu.children[i].style.opacity = 1;
				lunbotu.children[i].style.zIndex = 1;
			}
			else{
				lunbotu.children[i].style.opacity = 0;
				lunbotu.children[i].style.zIndex = 0;
//				lunbotu.children[i].timer1 = setInterval(function(){
//					if(op1<=0){
//						clearInterval(lunbotu.children[i].timer1);
//						op1=1;
//					}
//					op1-=0.1;
//					console.log(op1);
//					lunbotu.children[i].style.opacity = op1;
//					lunbotu.children[i].style.zIndex = op1;
//				},1000)
			}
		}
		index++;
		if(index==8){
			index = 0;
		}
	}
	function teshuTabimg(){
		for(var i = 0;i<lenlb;i++){
			if((index)==i){
				lunbotu.children[i].style.opacity = 1;
				lunbotu.children[i].style.zIndex = 1;	
			}else{
				lunbotu.children[i].style.opacity = 0;
				lunbotu.children[i].style.zIndex = 0;	
			}
		}
		index++;
	}
	
	/**
	 * 促销公告
	 */
	var news_tab_head = document.getElementsByClassName("news_tab_head");
	var news_tab_content_item = document.getElementsByClassName("news_tab_content_item");
	news_tab_head[0].children[0].onmouseenter = function(){
		news_tab_content_item[0].className = "news_tab_content_item news_tab_content_item_on";
		news_tab_content_item[1].className = "news_tab_content_item";
		news_tab_head[0].children[2].style.transform = "translateX(0px)";
	}
	news_tab_head[0].children[1].onmouseenter = function(){
		news_tab_content_item[1].className = "news_tab_content_item news_tab_content_item_on";
		news_tab_content_item[0].className = "news_tab_content_item";
		news_tab_head[0].children[2].style.transform = "translateX(52px)";
	}
	
	/**
	 * toolbar 右边栏
	 */
	var f_cart = document.getElementsByClassName("f_cart");
	var f_icon = document.getElementsByClassName("f_icon");
	var f_text = document.getElementsByClassName("f_text");
	var f_t_len = f_text.length;
	for(let i = 0;i<f_t_len;i++){
		f_cart[i].onmouseenter = function(){
			f_icon[i].style.backgroundColor = "#c81623";
			f_text[i].style.transform = "translateX(-95px)";
			f_text[i].style.backgroundColor = "#c81623";
			if(i==6){
				f_text[i].onclick = function(){
					document.documentElement.scrollTop = document.body.scrollTop = 0;
				}
			}
		}
		f_cart[i].onmouseleave = function(){
			f_text[i].style.transform = "translateX(35px)";
			f_icon[i].style.backgroundColor = "rgb(122,110,110)";
			f_text[i].style.backgroundColor = "rgb(122,110,110)";
		}
	}
}


window.onload = start;